<?php
class siteController extends baseController{

	private $_data = array();
	public function __construct(){
		parent::__construct();
	}

	public function __get($name){
		return isset( $this->_data[$name] ) ? $this->_data[$name] : NULL;
	}

	public function __set($name, $value){
		$this->_data[$name] = $value;
	}

	protected function error404(){
		header('HTTP/1.1 404 Not Found');
        header('Status: 404 Not Found');
		$this->show('404.html');
		exit;
	}

	//模板显示
	protected function show($tpl = '', $return = false, $is_tpl = true){
		if( $is_tpl ){
			$tpl = empty($tpl) ? CONTROLLER_NAME . '/'. ACTION_NAME : $tpl;
			if( $is_tpl && $this->layout ){
				$this->__template_file = $tpl;
				$tpl = $this->layout;
			}
			$tpl_array=explode('.', $tpl);
			$ext='.'.end($tpl_array);
			$name=substr($tpl,0,-intval(strlen($ext)));
		}

		$config=config('TPL');

		$tpl_dir=ROOT_PATH.$config['TPL_TEMPLATE_PATH'].$config['TPL_TEMPLATE_NAME'].'/';
		if(!file_exists($tpl_dir.$tpl)&&$tpl<>'404.html'){
			$appconfig=config('APP');
			if(!$appconfig['DEBUG']){
				$this->error404();
			}
		}
		$this->view()->config['TPL_TEMPLATE_PATH'] = $tpl_dir;
		$this->view()->config['TPL_TEMPLATE_SUFFIX'] = $ext;
		$this->view()->assign( $this->_data );
		$this->assign('config', config());
		return $this->view()->display($name, $return, $is_tpl);
	}


}